package cn.wsn2018.tools.service;

import cn.wsn2018.tools.common.CommonValue;
import cn.wsn2018.tools.mapper.RecommendMapper;
import cn.wsn2018.tools.model.Recommend;
import cn.wsn2018.tools.util.JsonUtil;
import net.sf.json.JSONArray;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@MapperScan("cn.wsn2018.tools.mapper")
@Service
/**
 * 处理安全策略建议的业务逻辑类
 */
public class RecommendService {
    @Resource
    private RecommendMapper recommendMapper;

    /**
     * 根据协议名罗列安全建议手段
     * @param protocolName
     * @return
     */
    public String dealListRecommends(String protocolName){
        List<Recommend> list=recommendMapper.listByProtocolName(protocolName);
        if(list.isEmpty()){
            return JsonUtil.failedJson(CommonValue.JSON_QUERY_RECOMMENDS_FAILED);
        }
        else{
            JSONArray arr=JSONArray.fromObject(list);
            return JsonUtil.successJson(CommonValue.JSON_QUERY_SUCCESS,null,arr);
        }
    }
}
